In [1]:
%pylab inline
from numpy.lib.recfunctions import append_fields, drop_fields, rename_fields
from astropy.io import fits
import os
In [2]:
x = np.genfromtxt('../input/fake_cluster/1118_real_clusters_withFeH.dat', dtype = None, names = True,
missing_values='""')
print(len(x),x.dtype.names)
x = append_fields(x, 'rvs', np.random.normal(0,10,len(x)), usemask=False, asrecarray=True)
x = np.sort(x,order = 'nbstars')
In [3]:
print(sum(x.nbstars))
# generate random mass (so that total number of stars < G18 is comparable to total number of generated stars)
mass = 300+np.abs(np.random.normal(0,500,len(x)))
print(np.mean(mass))
mass = np.sort(mass)
# Sort mass and vrot according to nbstars (more stars --> more mass --> higher vrot)
x = append_fields(x,'mass',mass,usemask=False, asrecarray=True)
# generate random speed at half light radius
vrot = np.sort(np.random.uniform(0.1,0.7,len(x)))
x = append_fields(x,'vrot',vrot,usemask=False, asrecarray=True)
In [4]:
plt.plot(x.mass,x.vrot,'.')
Out[4]:
In [5]:
# creating distances
distances = np.zeros(len(x))
for i in range(len(x)):
distances[i] = x.dmode[i]
if x.dmode[i] > 5000:
distances[i] = x.distance_Kharchenko[i]
In [6]:
fields_to_drop = ['l', 'b', 'nbstars', 'par', 'd05', 'd16',
'd84', 'd95','Rgc','rc_Kharchenko',
'rt_Kharchenko', 'FeH_Kharchenko','distance_Kharchenko', 'dmode']
x = drop_fields(x, fields_to_drop, usemask=False, asrecarray=True)
x = append_fields(x, 'distance_pc', distances, usemask=False, asrecarray=True)
In [7]:
# reformatting ages
x.logt_Kharchenko = np.power(10,x.logt_Kharchenko)/1e9
x = rename_fields(x,{"logt_Kharchenko":"age_gyr"})
# adding noise to synthetic feh
x.FeH_synth = np.random.normal(x.FeH_synth,0.1)
In [8]:
# generate random rotation axis
# random longitude
rangle = np.random.uniform(0,2*np.pi,len(x))
# random latitude
rz = []
count = False
for i in range(3*len(x)):
uniform = np.random.uniform(-0.5*np.pi,0.5*np.pi)
th = np.random.sample(1)
if th < np.cos(uniform):
rz.append(uniform)
rz = np.array(rz)[:len(x)] + np.pi/2
# transforming to the normal spin vektor
x0 = np.sin(rz) * np.cos(rangle)
y0 = np.sin(rz) * np.sin(rangle)
z0 = np.cos(rz)
x = append_fields(x,'x0',x0,usemask=False, asrecarray=True)
x = append_fields(x,'y0',y0,usemask=False, asrecarray=True)
x = append_fields(x,'z0',z0,usemask=False, asrecarray=True)
In [9]:
print(x.r50[0])
In [10]:
# half mass radius in physical units (r50 is arcdegree)
tan = np.tan(x.r50*(np.pi/180.))
hmrad = tan * distances
x.r50 = hmrad
#hmrad = np.divide(distances,57.3) * x.r50
In [11]:
print(x.dtype.names)
In [12]:
name = '../input/fake_cluster/cluster_for_processing.fits'
os.remove(name)
fits.writeto(name,x)
In [13]:
print(x.r50[0])
In [14]:
x.age_gyr
Out[14]:
In [ ]: